package edu.jvn.ict.locationsharing.informationexchange;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import edu.jvn.ict.locationsharing.MemberInfo;
import edu.jvn.ict.locationsharing.MemberServer;
import edu.jvn.ict.locationsharing.Utility;

public class GoingOfflineMessage extends ExchangeMessage{
	/**
	 * 
	 */
	public static final int MESSAGE_ID = 2;
	private static final long serialVersionUID = 8761195964927635709L;
	private long id;

	public GoingOfflineMessage(long id) {
		this.id = id;
	}
	
	public GoingOfflineMessage(String message) {
		this.id = Long.parseLong(message);
	}
	
	
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@Override
	public void process(ObjectInputStream in, ObjectOutputStream out)
			throws IOException {
		MemberInfo memberInfo = MemberServer.map.get(id);
		memberInfo.setNodeStatus(MemberInfo.OFFLINE);
		
		MemberServer.exchangeInformation(this, 1, false);		
	}
	
	public String toString(){
		return Utility.APP_START_MESSAGE + Integer.toString(MESSAGE_ID)+ "," + Long.toString(id);
	}
	
	
}
